var jichushuxing = {};
var jichushuxingshuzhi = {};
jichushuxing['布护腕'] = ['内功气盾', '外功气盾', '内功防御', '外功防御'];
jichushuxing['皮护腕'] = ['内功气盾', '外功气盾', '内功防御', '外功防御'];
jichushuxing['金属护腕'] = ['内功气盾', '外功气盾', '内功防御', '外功防御'];
jichushuxing['布头盔'] = ['内功防御', '外功防御', '气血上限'];
jichushuxing['皮头盔'] = ['内功防御', '外功防御', '气血上限'];
jichushuxing['金属头盔'] = ['内功防御', '外功防御', '气血上限'];
jichushuxing['布甲'] = ['内功防御', '外功防御', '气血上限'];
jichushuxing['皮甲'] = ['内功防御', '外功防御', '气血上限'];
jichushuxing['金属铠'] = ['内功防御', '外功防御', '气血上限'];
jichushuxing['腰带'] = ['基础气血百分比', '气血上限'];
jichushuxing['手套'] = ['基础气血百分比', '气血上限'];
jichushuxing['鞋子'] = ['内功防御', '外功防御', '内功格挡', '外功格挡'];

jichushuxing['内功戒指'] = ['内功攻击', '外功攻击'];
jichushuxing['内功手镯'] = ['内功命中', '外功命中'];
jichushuxing['内功项链'] = ['内功命中', '外功命中', '内功格挡', '外功格挡'];

jichushuxing['外功戒指'] = ['内功攻击', '外功攻击'];
jichushuxing['外功手镯'] = ['内功命中', '外功命中'];
jichushuxing['外功项链'] = ['内功命中', '外功命中', '内功格挡', '外功格挡'];

jichushuxing['武器'] = ['内功攻击', '外功攻击'];

jichushuxingshuzhi['布护腕'] = {};
jichushuxingshuzhi['皮护腕'] = {};
jichushuxingshuzhi['金属护腕'] = {};
jichushuxingshuzhi['布头盔'] = {};
jichushuxingshuzhi['皮头盔'] = {};
jichushuxingshuzhi['金属头盔'] = {};
jichushuxingshuzhi['布甲'] = {};
jichushuxingshuzhi['皮甲'] = {};
jichushuxingshuzhi['金属铠'] = {};
jichushuxingshuzhi['腰带'] = {};
jichushuxingshuzhi['手套'] = {};
jichushuxingshuzhi['鞋子'] = {};
jichushuxingshuzhi['内功戒指'] = {};
jichushuxingshuzhi['外功戒指'] = {};
jichushuxingshuzhi['内功手镯'] = {};
jichushuxingshuzhi['外功手镯'] = {};
jichushuxingshuzhi['内功项链'] = {};
jichushuxingshuzhi['外功项链'] = {};
jichushuxingshuzhi['武器'] = {};

//蓝，红，紫，百炼
jichushuxingshuzhi['布护腕']['内功气盾'] = [138, 175, 231, 250];
jichushuxingshuzhi['布护腕']['外功气盾'] = [138, 175, 231, 250];
jichushuxingshuzhi['布护腕']['内功防御'] = [37, 48, 67, 75];
jichushuxingshuzhi['布护腕']['外功防御'] = [32, 42, 58, 65];

jichushuxingshuzhi['皮护腕']['内功气盾'] = [138, 175, 231, 250];
jichushuxingshuzhi['皮护腕']['外功气盾'] = [138, 175, 231, 250];
jichushuxingshuzhi['皮护腕']['内功防御'] = [40, 51, 71, 80];
jichushuxingshuzhi['皮护腕']['外功防御'] = [40, 51, 71, 80];

jichushuxingshuzhi['金属护腕']['内功气盾'] = [138, 175, 231, 250];
jichushuxingshuzhi['金属护腕']['外功气盾'] = [138, 175, 231, 250];
jichushuxingshuzhi['金属护腕']['内功防御'] = [42, 54, 75, 84];
jichushuxingshuzhi['金属护腕']['外功防御'] = [47, 61, 83, 94];

jichushuxingshuzhi['布头盔']['内功防御'] = [43, 56, 77, 87];
jichushuxingshuzhi['布头盔']['外功防御'] = [38, 49, 68, 76];
jichushuxingshuzhi['布头盔']['气血上限'] = [751, 973, 1335, 1502];

jichushuxingshuzhi['皮头盔']['内功防御'] = [46, 60, 82, 93];
jichushuxingshuzhi['皮头盔']['外功防御'] = [46, 60, 82, 93];
jichushuxingshuzhi['皮头盔']['气血上限'] = [751, 973, 1335, 1502];

jichushuxingshuzhi['金属头盔']['内功防御'] = [49, 63, 87, 98];
jichushuxingshuzhi['金属头盔']['外功防御'] = [54, 70, 97, 109];
jichushuxingshuzhi['金属头盔']['气血上限'] = [751, 973, 1335, 1502];

jichushuxingshuzhi['布甲']['内功防御'] = [152, 198, 271, 305];
jichushuxingshuzhi['布甲']['外功防御'] = [133, 173, 237, 267];
jichushuxingshuzhi['布甲']['气血上限'] = [762, 988, 1355, 1524];
jichushuxingshuzhi['皮甲']['内功防御'] = [162, 210, 288, 324];
jichushuxingshuzhi['皮甲']['外功防御'] = [162, 210, 288, 324];
jichushuxingshuzhi['皮甲']['气血上限'] = [762, 988, 1355, 1524];
jichushuxingshuzhi['金属铠']['内功防御'] = [171, 222, 305, 343];
jichushuxingshuzhi['金属铠']['外功防御'] = [191, 247, 339, 382];
jichushuxingshuzhi['金属铠']['气血上限'] = [762, 988, 1355, 1524];

jichushuxingshuzhi['腰带']['基础气血百分比'] = [0.028, 0.037, 0.051, 0.057];
jichushuxingshuzhi['腰带']['气血上限'] = [1160, 1504, 2063, 2321];
jichushuxingshuzhi['手套']['基础气血百分比'] = [0.029, 0.037, 0.051, 0.057];
jichushuxingshuzhi['手套']['气血上限'] = [1177, 1526, 2093, 2355];
jichushuxingshuzhi['鞋子']['内功防御'] = [54, 70, 96, 109];
jichushuxingshuzhi['鞋子']['外功防御'] = [54, 70, 96, 109];
jichushuxingshuzhi['鞋子']['内功格挡'] = [94, 121, 167, 188];
jichushuxingshuzhi['鞋子']['外功格挡'] = [94, 121, 167, 188];

jichushuxingshuzhi['内功戒指']['内功攻击'] = [
    [44, 103],
    [57, 133],
    [78, 183],
    [88, 206]
];
jichushuxingshuzhi['内功戒指']['外功攻击'] = [
    [44, 103],
    [57, 133],
    [78, 183],
    [88, 206]
];
jichushuxingshuzhi['外功戒指']['内功攻击'] = [
    [44, 103],
    [57, 133],
    [78, 183],
    [88, 206]
];
jichushuxingshuzhi['外功戒指']['外功攻击'] = [
    [44, 103],
    [57, 133],
    [78, 183],
    [88, 206]
];

jichushuxingshuzhi['内功手镯']['内功命中'] = [55, 71, 98, 110];
jichushuxingshuzhi['内功手镯']['外功命中'] = [55, 71, 98, 110];
jichushuxingshuzhi['外功手镯']['内功命中'] = [55, 71, 98, 110];
jichushuxingshuzhi['外功手镯']['外功命中'] = [55, 71, 98, 110];

jichushuxingshuzhi['内功项链']['内功命中'] = [28, 36, 49, 56];
jichushuxingshuzhi['内功项链']['外功命中'] = [28, 36, 49, 56];
jichushuxingshuzhi['内功项链']['内功格挡'] = [42, 54, 74, 84];
jichushuxingshuzhi['内功项链']['外功格挡'] = [42, 54, 74, 84];

jichushuxingshuzhi['外功项链']['内功命中'] = [28, 36, 49, 56];
jichushuxingshuzhi['外功项链']['外功命中'] = [28, 36, 49, 56];
jichushuxingshuzhi['外功项链']['内功格挡'] = [42, 54, 74, 84];
jichushuxingshuzhi['外功项链']['外功格挡'] = [42, 54, 74, 84];

jichushuxingshuzhi['武器']['内功攻击'] = [
    [119, 278],
    [154, 360]
];
jichushuxingshuzhi['武器']['外功攻击'] = [
    [119, 278],
    [154, 360]
];

jichushuxingshuzhi['蒲元·菱形刃'] = [
    [169, 395],
    [178, 415],
    [209, 489],
    [219, 512],
    [186, 435]
];
jichushuxingshuzhi['高仙芝·镔铁护手'] = [
    [169, 395],
    [178, 415],
    [209, 489],
    [219, 512],
    [186, 435]
];
jichushuxingshuzhi['王彦章·蛇矛刺'] = [
    [169, 395],
    [178, 415],
    [209, 489],
    [219, 512],
    [186, 435]
];
jichushuxingshuzhi['雷海清·引梅剑'] = [
    [169, 395],
    [178, 415],
    [209, 489],
    [219, 512],
    [186, 435]
];
jichushuxingshuzhi['徐之才·清商坠环'] = [
    [169, 395],
    [178, 415],
    [209, 489],
    [219, 512],
    [186, 435]
];
jichushuxingshuzhi['嬴驷·春冰长剑'] = [
    [169, 395],
    [178, 415],
    [209, 489],
    [219, 512],
    [186, 435]
];
jichushuxingshuzhi['麻姑·蟾光灯盏'] = [
    [169, 395],
    [178, 415],
    [209, 489],
    [219, 512],
    [186, 435]
];


jichushuxingshuzhi['豫让·速刃'] = [
    [180, 420],
    [189, 441],
    [223, 520],
    [233, 544],
    [198, 462]
];
jichushuxingshuzhi['张飞·瓮金护手'] = [
    [180, 420],
    [189, 441],
    [223, 520],
    [233, 544],
    [198, 462]
];
jichushuxingshuzhi['穆桂英·蟠龙刺'] = [
    [180, 420],
    [189, 441],
    [223, 520],
    [233, 544],
    [198, 462]
];
jichushuxingshuzhi['蔡邕·焦尾剑'] = [
    [180, 420],
    [189, 441],
    [223, 520],
    [233, 544],
    [198, 462]
];
jichushuxingshuzhi['刘涓子·碧牙坠环'] = [
    [180, 420],
    [189, 441],
    [223, 520],
    [233, 544],
    [198, 462]
];
jichushuxingshuzhi['钩弋夫人·飞光长剑'] = [
    [180, 420],
    [189, 441],
    [223, 520],
    [233, 544],
    [198, 462]
];
jichushuxingshuzhi['葛玄·楼月灯盏'] = [
    [180, 420],
    [189, 441],
    [223, 520],
    [233, 544],
    [198, 462]
];


jichushuxingshuzhi['曹彬·陈刃'] = [
    [212, 494],
    [222, 519],
    [262, 612],
    [274, 640],
    [233, 544]
];
jichushuxingshuzhi['马援·镔铁护手'] = [
    [212, 494],
    [222, 519],
    [262, 612],
    [274, 640],
    [233, 544]
];
jichushuxingshuzhi['姜维·火龙刺'] = [
    [212, 494],
    [222, 519],
    [262, 612],
    [274, 640],
    [233, 544]
];
jichushuxingshuzhi['张文收·景云剑'] = [
    [212, 494],
    [222, 519],
    [262, 612],
    [274, 640],
    [233, 544]
];
jichushuxingshuzhi['公乘阳庆·兰皋坠环'] = [
    [212, 494],
    [222, 519],
    [262, 612],
    [274, 640],
    [233, 544]
];
jichushuxingshuzhi['兰陵老人·风波长剑'] = [
    [212, 494],
    [222, 519],
    [262, 612],
    [274, 640],
    [233, 544]
];
jichushuxingshuzhi['葛洪·急雪灯盏'] = [
    [212, 494],
    [222, 519],
    [262, 612],
    [274, 640],
    [233, 544]
];

// /_(.)\'>.\./

$('#b_load_lastzhiye').click(function () {
    zhiye = maindata.zhiye.zhiye;
    zhiyeshuxing = maindata.zhiye.zhiyeshuxing;
    $('#b_choose_zhiye').html("当前职业：" + zhiye);
    var t = ["碎梦", "血河", "铁衣", "神相", "龙吟", "素问", "九灵"];
    var b = t.indexOf(zhiye);
    $('#choose_zhiye')[0].options[b].selected = true;
});

function create_jichushuxing(leixing1, leixing2, pinzhi, extra, pingfen, adds) {
    var t = "";
    var allpoint = 0;

    if (!adds) adds = 1;

    if (leixing1 === '防具') {
        var keys = jichushuxing[leixing2];
        $.each(keys, function (n, v) {
            var values = jichushuxingshuzhi[leixing2][v];
            var maxvalue = 0;
            if (pinzhi === '蓝色') {
                maxvalue = values[0];
            } else if (pinzhi === '红色') {
                maxvalue = values[1];
            } else if (pinzhi === '紫色') {
                maxvalue = values[2];
            } else if (pinzhi === '百炼') {
                maxvalue = values[3];
            }
            maxvalue = maxvalue * adds;
            var middlevalue = 0;
            var finalvalue = 0;
            var displayvalue = "";
            var displaymaxvalue = "";
            if (maxvalue < 1) {
                var t1 = parseInt(maxvalue * 1000 * 0.65);
                var t2 = maxvalue * 1000;
                finalvalue = random(t1, t2);
                var tpoint = jisuanfangjupingfen('防具', v, finalvalue, pinzhi);
                allpoint += tpoint;
                finalvalue /= 1000;
                displayvalue = (finalvalue * 100).toFixed(1) + "%";
                displaymaxvalue = (maxvalue * 100).toFixed(1) + "%";
            } else {
                middlevalue = parseInt(maxvalue * 0.65);
                finalvalue = random(middlevalue, maxvalue);
                var tpoint = jisuanfangjupingfen('防具', v, finalvalue, pinzhi);
                allpoint += tpoint;
                displayvalue = finalvalue.toFixed(0);
                displaymaxvalue = maxvalue.toFixed(0);
            }

            t += '<span class="item_jichu">' + v + '：</span>' + displayvalue + '<span class="item_jichu">(' + displaymaxvalue + ')</span><br/>';


        });


    } else if (leixing1.indexOf('首饰') !== -1) {
        if (leixing2.indexOf('手镯') !== -1 || leixing2.indexOf('项链') !== -1) {
            var keys = jichushuxing[leixing2];
            $.each(keys, function (n, v) {
                var values = jichushuxingshuzhi[leixing2][v];
                var maxvalue = 0;
                if (pinzhi === '蓝色') {
                    maxvalue = values[0];
                } else if (pinzhi === '红色') {
                    maxvalue = values[1];
                } else if (pinzhi === '紫色') {
                    maxvalue = values[2];
                } else if (pinzhi === '百炼') {
                    maxvalue = values[3];
                }
                maxvalue = maxvalue * adds;
                var middlevalue = 0;
                var finalvalue = 0;
                var displayvalue = "";
                var displaymaxvalue = "";

                middlevalue = parseInt(maxvalue * 0.65);
                finalvalue = random(middlevalue, maxvalue);
                var tpoint = jisuanfangjupingfen(leixing2, v, finalvalue, pinzhi);
                allpoint += tpoint;
                displayvalue = finalvalue.toFixed(0);
                displaymaxvalue = maxvalue.toFixed(0);


                t += '<span class="item_jichu">' + v + '：</span>' + displayvalue + '<span class="item_jichu">(' + displaymaxvalue + ')</span><br/>';


            });


        } else if (leixing2.indexOf('戒指') !== -1) {
            var keys = jichushuxing[leixing2];
            $.each(keys, function (n, v) {
                var values = jichushuxingshuzhi[leixing2][v];
                var maxvalue = [0, 0];
                if (pinzhi === '蓝色') {
                    maxvalue = values[0];
                } else if (pinzhi === '红色') {
                    maxvalue = values[1];
                } else if (pinzhi === '紫色') {
                    maxvalue = values[2];
                } else if (pinzhi === '百炼') {
                    maxvalue = values[3];
                }
                var tmax1 = maxvalue[0] * adds;
                var tmax2 = maxvalue[1] * adds;

                var middlevalue = 0;
                var finalvalue = 0;
                var displaymaxvalue = "";
                var displayminvalue = "";


                middlevalue = parseInt(tmax1 * 0.65);
                finalvalue = random(middlevalue, tmax1);

                displayminvalue = finalvalue.toFixed(0);

                middlevalue = parseInt(tmax2 * 0.65);
                finalvalue = random(middlevalue, tmax2);
                var tpoint = jisuanfangjupingfen(leixing2, v, finalvalue, pinzhi);
                allpoint += tpoint;
                displaymaxvalue = finalvalue.toFixed(0);


                t += '<span class="item_jichu">' + v + '：</span>' + displayminvalue + ' - ' + displaymaxvalue + '<span class="item_jichu">(' + tmax1.toFixed(0) + ' - ' + tmax2.toFixed(0) + ')</span><br/>';


            });

        }

    } else {
        var keys = jichushuxing['武器'];
        if (pinzhi === '百炼') {
            var patten = /_(.)'>/;
            var pat = />(.{2,4}·.*)</;

            var b = extra.split('<br/>');
            var ret = patten.exec(b[2]);
            var flag = ret[1];
            ret = pat.exec(b[2]);
            var bjname = ret[1];
            var maxvalue = [0, 0];
            if (flag === '5') {
                maxvalue = jichushuxingshuzhi[bjname][2];
            } else if (flag === '6') {
                maxvalue = jichushuxingshuzhi[bjname][3];
            }
            var tmax1 = maxvalue[0] * adds;
            var tmax2 = maxvalue[1] * adds;
            $.each(keys, function (n, v) {
                var middlevalue = 0;
                var finalvalue = 0;
                var displaymaxvalue = "";
                var displayminvalue = "";


                middlevalue = parseInt(tmax1 * 0.65);
                finalvalue = random(middlevalue, tmax1);

                displayminvalue = finalvalue.toFixed(0);

                middlevalue = parseInt(tmax2 * 0.65);
                finalvalue = random(middlevalue, tmax2);
                var tpoint = jisuanfangjupingfen(leixing2, v, finalvalue, pinzhi);
                allpoint += tpoint;
                displaymaxvalue = finalvalue.toFixed(0);


                t += '<span class="item_jichu">' + v + '：</span>' + displayminvalue + ' - ' + displaymaxvalue + '<span class="item_jichu">(' + tmax1.toFixed(0) + ' - ' + tmax2.toFixed(0) + ')</span><br/>';

            });

        } else if (pinzhi === '紫色') {
            var patten = /_(.)'>/;
            var pat = />(.{2,4}·.*)</;

            var b = extra.split('<br/>');
            var ret = patten.exec(b[2]);
            var flag = ret[1];
            ret = pat.exec(b[2]);
            var bjname = ret[1];
            var maxvalue = [0, 0];
            if (flag === '3') {
                maxvalue = jichushuxingshuzhi[bjname][0];
            } else if (flag === '4') {
                maxvalue = jichushuxingshuzhi[bjname][1];
            } else if (flag === '5') {
                maxvalue = jichushuxingshuzhi[bjname][4];
            }
            var tmax1 = maxvalue[0] * adds;
            var tmax2 = maxvalue[1] * adds;
            $.each(keys, function (n, v) {
                var middlevalue = 0;
                var finalvalue = 0;
                var displaymaxvalue = "";
                var displayminvalue = "";


                middlevalue = parseInt(tmax1 * 0.65);
                finalvalue = random(middlevalue, tmax1);

                displayminvalue = finalvalue.toFixed(0);

                middlevalue = parseInt(tmax2 * 0.65);
                finalvalue = random(middlevalue, tmax2);
                var tpoint = jisuanfangjupingfen(leixing2, v, finalvalue, pinzhi);
                allpoint += tpoint;
                displaymaxvalue = finalvalue.toFixed(0);


                t += '<span class="item_jichu">' + v + '：</span>' + displayminvalue + ' - ' + displaymaxvalue + '<span class="item_jichu">(' + tmax1.toFixed(0) + ' - ' + tmax2.toFixed(0) + ')</span><br/>';

            });
        } else {
            var keys = jichushuxing['武器'];
            $.each(keys, function (n, v) {
                var values = jichushuxingshuzhi['武器'][v];
                var maxvalue = [0, 0];
                if (pinzhi === '蓝色') {
                    maxvalue = values[0];
                } else if (pinzhi === '红色') {
                    maxvalue = values[1];
                }
                var tmax1 = maxvalue[0] * adds;
                var tmax2 = maxvalue[1] * adds;
                var middlevalue = 0;
                var finalvalue = 0;
                var displaymaxvalue = "";
                var displayminvalue = "";


                middlevalue = parseInt(tmax1 * 0.65);
                finalvalue = random(middlevalue, tmax1);

                displayminvalue = finalvalue.toFixed(0);

                middlevalue = parseInt(tmax2 * 0.65);
                finalvalue = random(middlevalue, tmax2);
                var tpoint = jisuanfangjupingfen(leixing2, v, finalvalue, pinzhi);
                allpoint += tpoint;
                displaymaxvalue = finalvalue.toFixed(0);


                t += '<span class="item_jichu">' + v + '：</span>' + displayminvalue + ' - ' + displaymaxvalue + '<span class="item_jichu">(' + tmax1.toFixed(0) + ' - ' + tmax2.toFixed(0) + ')</span><br/>';


            });

        }

    }

    pingfen[0] = allpoint;

    return t + '<br/>';

}

$('#b_reset_xuetong1').click(function () {
    if (xuetong1.length <= 0) return;
    xuetong1pingfen -= xuetong1jichupingfen;
    var tpoint = [];
    var adds = 1;
    $.each(xuetong1, function (n, v) {
        if (v.indexOf('逆水') !== -1) {
            adds += 0.3;
        }

        if (v.indexOf('凭风') !== -1) {
            adds += 0.15;
        }

    });
    xuetong1jichu = create_jichushuxing(xuetong1leixing1, xuetong1leixing2, xuetong1pinzhi, xuetong1extra, tpoint, adds);
    xuetong1pingfen += tpoint[0];
    xuetong1jichupingfen = tpoint[0];

    xuetong1chuli();


    new $.zui.Messager('洗练成功！', {
        type: 'success',
        //placement: 'center',
        icon: 'ok-sign'
    }).show();
});

$('#b_reset_xuetong2').click(function () {
    if (xuetong2.length <= 0) return;
    xuetong2pingfen -= xuetong2jichupingfen;
    var tpoint = [];
    var adds = 1;
    $.each(xuetong2, function (n, v) {
        if (v.indexOf('逆水') !== -1) {
            adds += 0.3;
        }

        if (v.indexOf('凭风') !== -1) {
            adds += 0.15;
        }

    });
    xuetong2jichu = create_jichushuxing(xuetong2leixing1, xuetong2leixing2, xuetong2pinzhi, xuetong2extra, tpoint, adds);
    xuetong2pingfen += tpoint[0];
    xuetong2jichupingfen = tpoint[0];

    xuetong2chuli();


    new $.zui.Messager('洗练成功！', {
        type: 'success',
        //placement: 'center',
        icon: 'ok-sign'
    }).show();
});